package com.gomtel.smartdevice.ui.activity.tools;

import android.view.View;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

import com.gomtel.smartdevice.R;
import com.gomtel.smartdevice.base.WatchAppBaseActivity;
import com.gomtel.smartdevice.bean.UserContent;
import com.gomtel.smartdevice.moudle.db.entity.AtrialFibrillationInfo;
import com.gomtel.smartdevice.moudle.db.entity.BdDataInfo;
import com.gomtel.smartdevice.moudle.db.entity.EcgDataInfo;
import com.gomtel.smartdevice.moudle.event.CommonEvent;
import com.gomtel.smartdevice.ui.adapter.AdapterStandardGeneral;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/5/26 0026.
 */

public class SignsOfHistoryActivity extends WatchAppBaseActivity implements View.OnClickListener {

    @BindView(R.id.img_btn_black)
    ImageButton img_btn_black;
    @BindView(R.id.title_name)
    TextView title_name;
    @BindView(R.id.history_list)
    ListView history_list;

    @BindView(R.id.view_1)
    TextView view_1;
    @BindView(R.id.view_2)
    TextView view_2;
    @BindView(R.id.view_3)
    TextView view_3;
    @BindView(R.id.view_4)
    TextView view_4;
    @BindView(R.id.view_5)
    TextView view_5;

    private ArrayList<TextView> viewList = new ArrayList<>();
    private int actionType;
    private String type1[] = {"HRV状态", "生理年龄", "压力指数", "疲劳指数", ""};
    private String type2[] = {"收缩压", "舒张压", "", "", ""};
    private String type3[] = {"房颤", "心率", "", "", ""};
    private List<EcgDataInfo> ecgDataInfos;
    private ArrayList<Object> objects = new ArrayList<>();
    private AdapterStandardGeneral adapterStandardGeneral;
    private List<BdDataInfo> bdDataInfos;
    private List<AtrialFibrillationInfo> atrialFibrillationInfos;

    @Override
    protected void registerEvent(CommonEvent commonevent) {

    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_signs_of_history;
    }

    @Override
    protected void initClass() {
        actionType = Integer.valueOf(getIntent().getStringExtra("ActionType"));
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        title_name.setText(getString(R.string.history));
        switch (actionType) {
            case 0:
                initTitle(type1);
                ecgDataInfos = dataManager.queryEcgDataInfo(UserContent.UserName);
                if (ecgDataInfos != null) {
                    Collections.reverse(ecgDataInfos);
                    objects.addAll(ecgDataInfos);
                }
                break;
            case 1:
                initTitle(type2);
                bdDataInfos = dataManager.queryBdDataInfo(UserContent.UserName);
                if (bdDataInfos != null) {
                    Collections.reverse(bdDataInfos);
                    objects.addAll(bdDataInfos);
                }
                break;
            case 2:
                initTitle(type3);
                atrialFibrillationInfos = dataManager.queryAtrialFibrillationALLInfo(UserContent.UserName);
                if (atrialFibrillationInfos != null) {
                    Collections.reverse(atrialFibrillationInfos);
                    objects.addAll(atrialFibrillationInfos);
                }
                break;
        }
        adapterStandardGeneral = new AdapterStandardGeneral(objects, this);
        history_list.setAdapter(adapterStandardGeneral);
    }

    @Override
    protected void initListener() {
        img_btn_black.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_btn_black:
                finish();
                break;
        }
    }

    private void initTitle(String type[]) {
        viewList.add(view_1);
        viewList.add(view_2);
        viewList.add(view_3);
        viewList.add(view_4);
        viewList.add(view_5);
        for (int i = 0; i < viewList.size(); i++) {
            viewList.get(i).setText(type[i]);
        }
    }
}
